<?php

require_once 'Phlickr/Api.php';
require_once 'Phlickr/Framework/ListBase.php';

class Phlickr_Exif extends Phlickr_Framework_ListBase{
	
    const XML_RESPONSE_LIST_ELEMENT = 'photo';
    const XML_RESPONSE_ELEMENT = 'exif';
    const XML_METHOD_NAME = 'flickr.photos.getExif';
	
    function __construct(Phlickr_Request $request) {
        parent::__construct($request, self::XML_RESPONSE_ELEMENT,
            self::XML_RESPONSE_LIST_ELEMENT);
    }

    static function getRequestMethodName() {
        return self::XML_METHOD_NAME;
    }

    static function getRequestMethodParams($id) {
        return array('photo_id' => (string) $id);
    }

    public function getCount() {
        if (!isset($this->_cachedXml->exif)) {
            $this->load();
        }
        $ret = 0;
        foreach ($this->_cachedXml->exif as $exif) {
			print $exif['label'];
            $ret++;
        }
        return $ret;
    }

	public function find($label, $raw=false){
		foreach($this->_cachedXml->exif as $exif){
			if($exif['label'] == $label){
				if($raw){
					return $exif->raw;
				}else{
					return $exif->clean;
				}
			}
		}
		return "No exif data for label: $label";
	}
	
	/* param: array of exif labels -> clean/raw
	 * ret: array of exif label -> clean/raw value
	 *
	 */
	public function findLabels($labels){
		$r = array();
		foreach($labels as $label=>$raw){
			$r[$label] = $this->find($label, $raw);
		}
		return $r;
	}

	public function getExposure(){
		return $this->find("Exposure", true);
	}
	
	public function getAperture(){
		return $this->find("Aperture");
	}
	
	public function getFocalLength(){
		return $this->find("Focal Length");
	}
	
	public function getIsoSpeed(){
		return $this->find("ISO Speed", true);
	}
}